package com.itheima.dao;

import com.itheima.domain.Student;

public class StudentDao {
    private Student student;
    private StudentDao nextIndex;
    private static int size=0;

   // static{
      public static  StudentDao headIndex =null;
   // }


   public StudentDao(Student student) {
       this.student = student;
       this.size++;
       this.nextIndex=null;

   }

    public StudentDao() {
        this.nextIndex=null;
    }

    public Student getStudent() {
        return student;
    }

    public StudentDao getNextIndex() {
        return nextIndex;
    }

    public static int getSize() {
        return size;
    }

    public static StudentDao getHeadIndex() {
        return headIndex;
    }


    public void setStudent(Student student) {
        this.student = student;
    }

    public void setNextIndex(StudentDao nextIndex) {
        this.nextIndex = nextIndex;
    }

    public static void setSize(int size) {
        StudentDao.size = size;
    }

    //数据访问层添加新的数据
    public StudentDao addStudent(Student student){
       //判断下级指针是否为空
      if(this.getNextIndex()==null){
          this.setNextIndex(new StudentDao(student));
          StudentDao.size++;
      }else{
          this.getNextIndex().addStudent(student);
      }
      headIndex=this;
      return this;
    }
    //数据访问层删除节点
    public void deleteStudent(StudentDao deleteIndex) {

        StudentDao next=deleteIndex.getNextIndex().nextIndex;
        deleteIndex.setNextIndex(next);
        StudentDao.size--;
    }
    //数据访问层修改节点
    public void updateStudent(StudentDao index,Student student) {
       index.getNextIndex().setStudent(student);
    }
}
